//
//  YQStatusOriginalView.m
//  WeiboOC
//
//  Created by yang on 15/11/19.
//  Copyright © 2015年 yang. All rights reserved.
//

#import "YQStatusOriginalView.h"
#import "YQStatus.h"
@interface YQStatusOriginalView ()
//cell 间的分隔条
@property (nonatomic, strong) UIView* sepView;
//用户头像
@property (nonatomic, strong) UIImageView* iconImage;
//用户名
@property (nonatomic, strong) UILabel* nameLabel;
//用户等级
@property (nonatomic, strong) UIImageView* memberIconView;
//用认证类型户
@property (nonatomic, strong) UIImageView* verifiedIconView;
//发布时间
@property (nonatomic, strong) UILabel* timeLabel;
//微博来源
@property (nonatomic, strong) UILabel* sourceLabel;
//微博正文
@property (nonatomic, strong) UILabel* contentLabel;
@property (nonatomic, strong)  YQStatusPictureView*pictureView;
@property (nonatomic, strong)  MASConstraint *bottomConstraints;
@end
@implementation YQStatusOriginalView
-(void)setOriginalStatus:(YQStatus *)originalStatus{
    _originalStatus = originalStatus;
    [self.iconImage sd_setImageWithURL:originalStatus.user.headImageURL placeholderImage: [UIImage imageNamed:@"avatar_default_big"]];
    self.nameLabel.text = originalStatus.user.name;
    self.memberIconView.image = originalStatus.user.mbrankImage;
    self.verifiedIconView.image = originalStatus.user.verified_typeImage;
    self.timeLabel.text = @"11:11";// originalStatus.created_at;
    self.sourceLabel.text =@"刘涛";// originalStatus.source;
    self.contentLabel.text = originalStatus.text;
    [self.bottomConstraints uninstall];
    if (originalStatus.imageURLs.count != 0) {
        self.pictureView.imageURLs = originalStatus.imageURLs;
        self.pictureView.hidden = NO;
        [self updateConstraints:^(MASConstraintMaker *make) {
          self.bottomConstraints = make.bottom.equalTo(self.pictureView.bottom).equalTo(StatusCellMargin);
        }];
    }else{
        self.pictureView.hidden = YES;
        [self updateConstraints:^(MASConstraintMaker *make) {
          self.bottomConstraints = make.bottom.equalTo(self.contentLabel.bottom).equalTo(StatusCellMargin);
        }];

    }
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI{
    [self addSubview:self.sepView];
    [self addSubview:self.iconImage];
    [self addSubview:self.nameLabel];
    [self addSubview:self.memberIconView];
    [self addSubview:self.verifiedIconView];
    [self addSubview:self.timeLabel];
    [self addSubview:self.sourceLabel];
    [self addSubview:self.contentLabel];
    [self addSubview:self.pictureView];
    self.iconImage.layer.cornerRadius = StatusCellIconWitdth / 2;
    self.iconImage.layer.masksToBounds = YES;
    [self.sepView makeConstraints:^(MASConstraintMaker* make) {
        make.top.left.right.equalTo(self);
        make.height.equalTo(20);
    }];
    [self.iconImage makeConstraints:^(MASConstraintMaker* make) {
        make.top.equalTo(self.sepView.bottom).offset(StatusCellMargin);
        make.left.equalTo(self.sepView).offset(StatusCellMargin);
        make.height.width.equalTo(StatusCellIconWitdth);
    }];
    [self.nameLabel makeConstraints:^(MASConstraintMaker* make) {
        make.top.equalTo(self.iconImage);
        make.left.equalTo(self.iconImage.right).offset(StatusCellMargin);
    }];
    [self.memberIconView makeConstraints:^(MASConstraintMaker* make) {
        make.top.equalTo(self.iconImage);
        make.left.equalTo(self.nameLabel.right).offset(StatusCellMargin);
    }];
    [self.verifiedIconView makeConstraints:^(MASConstraintMaker* make) {
        make.centerX.equalTo(self.iconImage.right);
        make.centerY.equalTo(self.iconImage.bottom);
    }];
    [self.timeLabel makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(self.iconImage.right).offset(StatusCellMargin);
        make.bottom.equalTo(self.iconImage);
    }];
    [self.sourceLabel makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(self.timeLabel.right).offset(StatusCellMargin);
        make.bottom.equalTo(self.iconImage);
    }];
    [self.contentLabel makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(self.iconImage);
        make.top.equalTo(self.iconImage.bottom).offset(StatusCellMargin);
    }];
    [self.pictureView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentLabel);
        make.top.equalTo(self.contentLabel.bottom).offset(StatusCellMargin);
    }];
    [self makeConstraints:^(MASConstraintMaker* make) {
       self.bottomConstraints = make.bottom.equalTo(self.pictureView.bottom).offset(StatusCellMargin);
    }];

}
#pragma mark - 懒加载子控件
- (UIView*)sepView
{
    if (!_sepView) {
        _sepView = [[UIView alloc] init];
        _sepView.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1];
    }
    return _sepView;
}
- (UIImageView*)iconImage
{
    if (!_iconImage) {
        _iconImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"avatar_default_big"]];
    }
    return _iconImage;
}
- (UILabel*)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithTitle:@"淡淡的月光" size:14 color:[UIColor darkGrayColor] margin:0];
    }
    return _nameLabel;
}
- (UIImageView*)memberIconView
{
    if (!_memberIconView) {
        _memberIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"common_icon_membership_level1"]];
    }
    return _memberIconView;
}
- (UIImageView*)verifiedIconView
{
    if (!_verifiedIconView) {
        _verifiedIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"avatar_vip"]];
    }
    return _verifiedIconView;
}
- (UILabel*)timeLabel
{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] initWithTitle:@"11:11" size:10 color:[UIColor orangeColor] margin:0];
    }
    return _timeLabel;
}
- (UILabel*)sourceLabel
{
    if (!_sourceLabel) {
        _sourceLabel = [[UILabel alloc] initWithTitle:@"来自: 刘涛" size:10 color:[UIColor lightGrayColor] margin:0];
    }
    return _sourceLabel;
}
- (UILabel*)contentLabel
{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] initWithTitle:@"野内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮" size:14 color:[UIColor lightGrayColor] margin:StatusCellMargin];
    }
    return _contentLabel;
}
-(YQStatusPictureView *)pictureView{
    if (!_pictureView) {
        _pictureView = [[YQStatusPictureView alloc]init];
    }
    return _pictureView;
}
@end
